package com.springboot.result;

import lombok.Data;
import lombok.experimental.Accessors;

@Data
@Accessors(chain = true)
public class Result<T> {
    private int code;
    private String msg;
    private T data;


    public static <T> Result<T> success() {
        return new Result().setCode(ResultCodeEnum.SUCCESS.getCode())
                .setMsg(ResultCodeEnum.SUCCESS.getMessage());
    }

    public static <T> Result<T> success(T data) {
        return new Result<T>().setCode(ResultCodeEnum.SUCCESS.getCode())
                .setMsg(ResultCodeEnum.SUCCESS.getMessage())
                .setData(data);
    }

    public static <T> Result<T> success(T data, String msg) {
        return new Result<T>().setCode(ResultCodeEnum.SUCCESS.getCode())
                .setData(data)
                .setMsg(msg);
    }

    public static <T> Result<T> fail() {
        return new Result().setCode(ResultCodeEnum.FAIL.getCode())
                .setMsg(ResultCodeEnum.FAIL.getMessage());
    }

    public static <T> Result<T> fail(T data) {
        return new Result<T>().setCode(ResultCodeEnum.FAIL.getCode())
                .setMsg(ResultCodeEnum.FAIL.getMessage())
                .setData(data);
    }

    public static <T> Result<T> fail(T data, String msg) {
        return new Result<T>().setCode(ResultCodeEnum.FAIL.getCode())
                .setData(data)
                .setMsg(msg);
    }

}
